define(["jquery","login","register"],function($){
	function Header(){
		this.createDom();
		this.loadUser();
		this.addListener();
	}
	Header.Html=`<nav class="navbar navbar-inverse">
	    <!-- Brand and toggle get grouped for better mobile display -->
	    <div class="navbar-header">
	      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
	        <span class="icon-bar"></span>
	        <span class="icon-bar"></span>
	        <span class="icon-bar"></span>
	      </button>
	      <a class="navbar-brand" href="#">职位管理系统</a>
	    </div>

	    <!-- Collect the nav links, forms, and other content for toggling -->
	    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
	      <ul class="nav navbar-nav">
	        <li class="active"><a href="/">首页<span class="sr-only">(current)</span></a></li>
	        <li><a href="/html/position.html">职位管理</a></li>
	      </ul>
	      <ul class="nav navbar-nav navbar-right not-login">
	        <li data-toggle="modal" data-target="#loginModal">
	        	<a href="#">登录</a>
	        </li>
	        <li data-toggle="modal" data-target="#registerModal">
	        	<a href="#">注册</a>
	        </li>
	      </ul>
	      <ul class="nav navbar-nav navbar-right already-login hidden">
	        <li>
	        	<a href="#" class="link-user">登录</a>
	        </li>
	        <li>
	        	<a href="#" class="link-logout">退出</a>
	        </li>
	      </ul>
	    </div><!-- /.navbar-collapse -->
	  </nav><!-- /.container-fluid -->`;
	$.extend(Header.prototype,{
		createDom(){
			$(Header.Html).appendTo("header");
		},
		loadUser(){
			const username = sessionStorage.loginUser;
			if(username){
				$(".already-login").removeClass("hidden")
					.find(".link-user").text(username).end()
					.siblings(".not-login").remove();
			}
		},
		addListener(){
			$(".link-logout").on("click",this.logoutHandel);
		},
		logoutHandel(){
			const url = "http://rap2api.taobao.org/app/mock/119523/api/users/logout";
			$.get(url,(data)=>{
				sessionStorage.clear();
				location = "/";
			});
		}
	});
	return new Header();
});